<template>
  <div class="app-container">
    <el-form ref="queryForm" :model="queryParams" :inline="true" label-width="68px">

      <el-form-item label="网站名称" prop="title">
        <el-input v-model="queryParams.website_name" placeholder="请输入网站名称" clearable size="small" />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="list" style="width: 100%;" stripe highlight-current-row @sort-change="sortChange" @selection-change="handleSelectionChange">
      <!-- <el-table-column type="selection" align="center" width="50" /> -->
      <el-table-column label="ID" align="center" prop="id" width="50" />
      <el-table-column label="网站名称" align="center" prop="website_name" />
      <el-table-column label="Url" align="center" prop="website_url" />
      <el-table-column label="是否启用" align="center">
        <template v-slot="scoped">
          <el-tag v-if="scoped.row.status == '启用'" type="success">启用</el-tag>
          <el-tag v-else type="danger">禁用</el-tag>
        </template>

      </el-table-column>

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="150">
        <template v-slot="scope">
          <el-link v-if="scope.row.status == '启用'" type="danger" href="javascript:;" target="_blank" @click.prevent="updateStatus(scope.row)">禁用</el-link>
          <el-link v-if="scope.row.status == '禁用'" type="primary" href="javascript:;" target="_blank" @click="updateStatus(scope.row)">启用</el-link>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.page"
      :limit.sync="queryParams.limit"
      @pagination="getList"
    />
  </div>
</template>
<style>
.el-input__inner {
  width: 90%;
}

.el-input__suffix {
  right: 10%;
}
</style>
<script>
import { mapGetters } from 'vuex'
import clip from '@/utils/clipboard'
import { newsWebsiteList, newsWebsiteDisOrEnable } from '@/api/basics' // use clipboard directly

export default {
  name: 'Index',
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      open: false,
      title: '',
      // 总条数
      total: 0,
      // 表格数据
      list: [],
      portConfig: [],
      info: '',
      // 查询参数
      queryParams: {
        page: 1,
        limit: 10,
        title: undefined
      },
      options1: [],
      props: { checkStrictly: true, label: 'name', value: 'id' },
      category_ids: [],
      form: {},
      show: false,
      ids: [],
      multiple: false,
      dialogImageUrl: '',
      dialogVisible: false,
      fileList: [],
      url: undefined,
      open1: false,
      title1: '',
      form1: {},
      ifAdmin: false,
      cate_list: []
    }
  },
  created() {
    this.getList()
  },
  computed: {
    ...mapGetters([
      'token'
    ])
  },
  methods: {
    updateStatus(row) {
      const that = this
      newsWebsiteDisOrEnable(row.id).then(response => {
        if (response.code == 10000) {
          that.$notify({
            title: '成功',
            message: '状态修改成功',
            type: 'success'
          })
        }
      })
    },
    openAdd(row, type) {
      if (type === '添加') {
        this.open1 = true
        this.title1 = '添加'
        this.form1 = {}
      } else {
        this.open1 = true
        this.title1 = '编辑'
        this.form1 = row
      }
    },
    resetForm(formName) {
      this.$refs[formName].resetFields()
    },

    /** 查询清单列表 */
    getList() {
      console.log(this.queryParams)
      this.loading = true
      newsWebsiteList(this.queryParams).then(response => {
        this.list = response.data
        this.total = response.count
        this.loading = false
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.page = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams = {
        page: 1,
        limit: 10,
        brand_name: undefined
      }
      this.handleQuery()
    },
    /** 选中的项 */
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.multiple = !selection.length
    }
  }
}
</script>

